<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>条件渲染</title>
    <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
</head>

<body>
    <div id="app">
        <div v-if="Math.random() > 0.3">
            Now you see me0.3
        </div>
        <div v-else-if="Math.random() > 0.6">
            Now you see me0.6
        </div>
        <div v-else>
            Now you don't
        </div>

        <span v-if="loginType === 'username'">
            <label>Username</label>
            <input placeholder="Enter your username" key="username-input">
        </span>
        <span v-else>
            <label>Email</label>
            <input placeholder="Enter your email address" key="email-input">
        </span>
        <button v-on:click="test">切换</button>
        <!-- v-show元素总是会被渲染，并且只是简单地基于 CSS 进行切换。 -->
        <h1 v-show="ok">Hello!</h1>
    </div>

    <script>
        let app = new Vue({
            el: '#app',
            data:{
                loginType:'username',
                ok:false
            },
            methods:{
                test:function(){
                    if(this.loginType == 'username'){
                        return this.loginType = 'email'
                    }else{
                        return this.loginType = 'username'
                    }
                }
            }
        })
    </script>

</body>

</html>